{include file="public/header" /}
{load href="__PLUGINS__bootstrap/bootstrap-table.min.css"}
{load href="__PLUGINS__bootstrap/bootstrap-table.min.js"}
<style>
    #des, #des input {
        width: 40px;
        text-align: center;
    }

    #id {
        width: 78px;
    }

    .bs-checkbox {
        width: 36px;
        height: 40px
    }

    .fixed-table-toolbar .columns, .fixed-table-toolbar .search {
        margin-left: 0;
        margin-top: 0
    }

    #title span {
        float: right;
    }

    .asdlkjasd {
        background: #1ab394;
        color: #fff
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content {:config('adminClass.main')}">
    <div class="ibox float-e-margins">
        {include file="public/tophead"}
        {include file="public/top" /}
        <div class="ibox-content">
            {include file="public/topsection"}
            <div class="row row-lg">
                <div class="col-sm-12">
                    <div style="display:block;clear: both;"></div>
                    <div class="fixed-table-toolbar" style="text-align: center;margin-bottom: 20px">
                        <h2>变动总金额: <span style="color: #1ab394; ">{:number_format($sum,2)}</span></h2>
                    </div>
                    <div class="fixed-table-toolbar">
                        <a class="btn btn-default btn-outline {present name='toward'}{else /}asdlkjasd{/present}" href="{:url('records')}">全部</a>
                        <a class="btn btn-default btn-outline {eq name='toward' value='0'}asdlkjasd{/eq}" href="{:url('records',['toward'=>0])}">收入</a>
                        <a class="btn btn-default btn-outline {eq name='toward' value='1'}asdlkjasd{/eq}" href="{:url('records',['toward'=>1])}">支出</a>
                        <span style="float:right">
                        <a class="btn btn-default btn-outline {eq name='order' value='1'}asdlkjasd{/eq}"
                           href="{:url('records',['order'=>'1'])}{present name='toward'}/toward/{$toward}{/present}">默认排序</a>
                        <a class="btn btn-default btn-outline {eq name='order' value='2'}asdlkjasd{/eq}"
                           href="{:url('records',['order'=>'2'])}{present name='toward'}/toward/{$toward}{/present}">时间正序</a>
                        </span>
                    </div>
                    <div class="fixed-table-toolbar">
                        <form method="get" action="" style="display: flex;">
                            <div class="pull-left search" style="display: flex;">
                                <div class="columns columns-right btn-group pull-left">
                                    <select class="form-control" name="search">
                                        <option value="id" {php}if(input(
                                        '?param.search')){if(input('param.search')=='id'){echo "selected";}
                                        }{/php}>ID</option>
                                        <option value="name" {php}if(input(
                                        '?param.search')){if(input('param.search')=='name'){echo "selected";}
                                        }{/php}>昵称</option>
                                        <option value="phone" {php}if(input(
                                        '?param.search')){if(input('param.search')=='phone'){echo "selected";}
                                        }{/php}>手机</option>
                                        <option value="touid" {php}if(input(
                                        '?param.search')){if(input('param.search')=='touid'){echo "selected";}
                                        }{/php}>来源ID</option>
                                    </select>
                                </div>

                                <div class="pull-right search">
                                    <input class="form-control input-outline" type="text"
                                           {php}
                                           if(input('?param.name')){
                                    if(input('param.name')){
                                    echo "value='".input('name')."'";
                                    }
                                    }
                                    {/php}
                                    name="name" placeholder="搜索">
                                </div>
                                <div class="pull-right search" style="margin-left: 20px;">
                                    备注：
                                </div>
                                <div class="pull-right search">
                                    <input class="form-control input-outline" type="text" value="{$content}" name="content" placeholder="备注">
                                </div>

                                <div class="pull-right search">
                                    <button style="border-radius:0px; border:1px solid #e5e6e7; border-left:0px"
                                            class="btn btn-default btn-outline" type="submit">搜索
                                    </button>
                                </div>

                                <input name="start" type="text" id="start" class="form-control layui-input" value="{present name='start'}{$start}{/present}" placeholder=" # 起始时间" autocomplete="off" style="height:34px;width:180px;margin:0 10px 0 20px;">
                                <input name="end" type="text" id="end" class="form-control layui-input" value="{present name='end'}{$end}{/present}" placeholder=" # 结束时间" autocomplete="off" style="height:34px;width:180px;margin:0 10px;">

                                {php}
                                if(input('?param.name')){
                                {/php}
                                <div class="pull-right search">
                                    <a class="btn btn-w-m btn-link" href="{:url('records')}">返回列表</a>
                                </div>
                                {php}
                                }
                                {/php}

                            </div>
                        </form>
                    </div>
                    <div class="example">
                        <form class="form-horizontal" method="post">
                            <table data-toggle="table">
                                <thead>
                                <tr>
                                    <th class="bs-checkbox"><input type="checkbox" id="delidAll"></th>
                                    <th data-align="center">ID</th>
                                    <th data-align="center">用户</th>
                                    <th data-align="center">备注</th>
                                    <th data-align="center">变动积分</th>
                                    <th data-align="center">账户积分(剩余)</th>
                                    <th data-align="center">时间</th>
                                </tr>
                                </thead>
                                <tbody id="form">
                                {volist name="data" id="v"}
                                <tr id="id{$v.id}" class="class">
                                    <td id="delid" ><input name="delAll[]" type="checkbox" value="{$v.id}"></td>
                                    <td>{$v.id}</td>
                                    <td><a onclick="member('{$v.uid}')" style="color:#40BCF7">{$v.name}</a><br>(ID：{$v.uid})</td>
                                    <td>{$v.content}</td>
                                    <td>
                                        {switch name="$v.data"}
                                        {case value="0"}<span style="color: #1ab394; ">+{/case}
                                        {default /}<span style="color: #f00; ">-
                                            {/switch}
                                            {$v.money}</span>
                                    </td>
                                    <td><span style="color: #1ab394;">{$v.balance}</span></td>
                                    <td>
                                        <span {if condition="date('Ymd')==date('Ymd',$v.time)"}style="color: #ed5565"{/if}>{:date('Y-m-d H:i:s', $v.time)}</span>
                                    </td>
                                </tr>
                                {/volist}
                                </tbody>
                            </table>
                        </form>
                    </div>
                </div>
            </div>
            <hr>
            <div class="row row-lg">
                                                {eq name='admin.type' value='1'}
                <div class="col-sm-6">
                    <div  class="btn btn-outline btn-default" onclick="exportData()">
                        批量导出
                    </div>
                </div>
                                                {/eq}
                <div class="col-sm-12 pages">{$page}</div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
{load href="__PLUGINS__iCheck/icheck.min.js"}
{load href="__PLUGINS__iCheck/custom.css"}

<script type="text/javascript">
    $(document).ready(function(){

        $('#delidAll').click(function(){
            $('input[type=checkbox]').each(function(){
                var self=$(this);
                if(!self.prop('checked')){
                    self.prop('checked',true);
                }else{
                    self.prop('checked',false);
                }
            });
        })
    });

    layui.use(['laydate'], function(){
        var laydate = layui.laydate;

        laydate.render({
            elem: '#start' //指定元素
            ,type: 'datetime'
            ,trigger: 'click'
        });

        laydate.render({
            elem: '#end' //指定元素
            ,type: 'datetime'
            ,trigger: 'click'
        });
    })

    function member(id)
    {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['100%', '100%'],
                type: 2,
                content: '{:url("member/index")}?search=id&name='+id
            });
        });
    }

    var downing = false

    function exportData() {

        if(downing){
            return layer.msg('导出进程较慢，请勿频繁点击');
        }
        downing = true
        setTimeout(()=>{
            downing = false
        }, 10000)
        
        var url = "<?php echo $_SERVER['REQUEST_URI']; ?>";
        var order = "{$order}";

        var all = $(".form-horizontal").serialize();

        // if(!all){
        //     layer.msg("请选择需要导出的项！")
        //     return false
        // }

        window.location.href = '{:url("export/income")}?' + all + '&url=' + url + '&order=' + order;
    }
</script>
 